package com.ewanghuiju.app.presenter.home;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.home.InviteFriendContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.InviteFriendResponBean;
import com.ewanghuiju.app.model.bean.response.RuleBean;
import com.ewanghuiju.app.model.http.response.MyHttpResponse;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class 邀请好友
 * @time 2020/2/16
 */
public class InviteFriendPresenter extends RxPresenter<InviteFriendContract.View> implements InviteFriendContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public InviteFriendPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getData() {
        //获取邀请好友信息
        addSubscribe(mDataManager.getQrcodeInfo()
                .compose(RxUtil.<MyHttpResponse<InviteFriendResponBean>>rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<InviteFriendResponBean>>(mView) {
                    @Override
                    public void onNext(Optional<InviteFriendResponBean> userInfo) {
                        if (mView != null) {
                            mView.showContent(userInfo.getIncludeNull());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );

    }


    @Override
    public void getPtiguize(String type) {
        //获取规则
        addSubscribe(mDataManager.getPtiguize(type)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<RuleBean>>(mView) {
                    @Override
                    public void onNext(Optional<RuleBean> optional) {
                        if (mView != null)
                            mView.showPtiguize(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

}
